package com.ityuwen.mengyagushi.live.api;

import com.ityuwen.mengyagushi.common.login.GuiGuLogin;
import com.ityuwen.mengyagushi.common.result.Result;
import com.ityuwen.mengyagushi.live.service.LiveRoomService;
import com.ityuwen.mengyagushi.model.live.LiveRoom;
import com.ityuwen.mengyagushi.vo.live.LiveRoomVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("api/live/liveRoom")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LiveRoomApiController {

	@Autowired
	private LiveRoomService liveRoomService;

	@GuiGuLogin
	@GetMapping("getCurrentLive")
	public Result<LiveRoom> getCurrentLive(){
		LiveRoom liveRoom = this.liveRoomService.getCurrentLive();
		return Result.ok(liveRoom);
	}

	@GuiGuLogin
	@PostMapping("saveLiveRoom")
	public Result<LiveRoom> saveLiveRoom(@RequestBody LiveRoomVo roomVo){
		LiveRoom liveRoom = this.liveRoomService.saveLiveRoom(roomVo);
		return Result.ok(liveRoom);
	}

	@GetMapping("getById/{id}")
	public Result<LiveRoom> getById(@PathVariable("id")Long id){
		LiveRoom liveRoom = this.liveRoomService.getById(id);
		return Result.ok(liveRoom);
	}

	@GetMapping("findLiveList")
	public Result<List<LiveRoom>> findLiveList(){
		List<LiveRoom> liveRooms = this.liveRoomService.list(new LambdaQueryWrapper<LiveRoom>().gt(LiveRoom::getExpireTime, new Date()));
		return Result.ok(liveRooms);
	}
}

